#{extends 'mainStage.html' /}

#{set title:'Gérer les candidatures' /}
#{if admin || gestionnaireFonct}
<a href="@{Candidats.gestionCandidatures}">G&eacute;rer les candidatures > </a> Validation des candidatures
#{/if}
#{else}
<a href="@{Candidats.gestionCandidaturesTerri}">G&eacute;rer les candidatures > </a> Validation des candidatures
#{/else}
#{if candidatures}
<div class="post">
    <div class="post">
        <h2 class="post-title">
            Liste des candidatures pour le stage: ${stage.intitule}
        </h2>
         #{form @gestionCandidatureSave(params.get("stageId"))} 
           <table cellpadding="0" cellspacing="0" border="0" class="display" id="liste"> 
                <thead>
                    <tr>
                        <th>CIS Service</th>
                        <th>Nom</th>
                        <th>Prenom</th>	
                        <th>Grade</th>
                        <th>R&ocirc;le</th>
                        <th>Etat</th>
                        <th>Candidature partielle</th>
                        <th>Priorit&eacute;</th>
                        <th>Gestion du candidat</th>			
                    </tr>
                </thead>		

                <tbody>
                    #{list items:candidatures, as:'candidature' }
                        <tr>
                            <td>${candidature.agent.cisService}</td>
                            <td><a href="@{candidats.detailCandid(candidature.id)}">${candidature.agent.nom}</a></td>
                            <td>${candidature.agent.prenom}</td>
                            <td>${candidature.agent.grade}</td>
                            <td>${candidature.role}</td>
                            #{if candidature.etatCandid.nom.equals("Annulée") || candidature.etatCandid.nom.equals("Refusée")}
                    	<td style="background-color: RGB(228, 2, 22);">
                    #{/if}
                    #{elseif candidature.etatCandid.nom.equals("Validée")}
                    	<td style="background-color: RGB(0, 128, 0);">
                    #{/elseif}
                    #{elseif candidature.etatCandid.nom.equals("Liste d'attente")}
                    	<td style="background-color: RGB(255, 165, 0);">
                    #{/elseif}
                    #{else}
                    	<td> 
                    #{/else}
								${candidature.etatCandid}
							</td>
                            <td>
                            #{if candidature.candidPartielle}
		                    	oui
		                    	#{list candidature.examenUv, as:'uv'}
		                    		</br>${uv}
		                    	#{/list}
		                    #{/if}
		                    #{else}
		                    	non
		                    #{/else}
		                    </td>
		                    <td id="tdChange${candidature.id}">
				   		<div style="display:none" id="listePriorite${candidature.id}">
				   			<select id="priorite${candidature.id}" name="priorite${candidature.id}" onchange="savePriorite(${candidature.id})" style="width:auto;">
				   				<option>-- Priorit&eacute; --</option>
				   			#{list priorites, as:'priorite'}
				   				<option value="${priorite.id}">${priorite.ordre}</option> 
				   			#{/list}
				   			</select>
				   		</div>
				   		#{if candidature.ordrePrioriteGrpmt!=null}
				   			${candidature.ordrePrioriteGrpmt}
				   		#{/if}
				   		#{else}
				   			-
				   		#{/else}
				   		<a href="#" onClick="afficherList(${candidature.id})">Modifier</a>
				   	</td>
                            <td>
                                Valider :<input type="radio" name="validation_${candidature.id}" id="validation_${candidature.id}" value="validee" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" /><br/>
                                Annuler :<input type="radio" name="validation_${candidature.id}" id="validation_${candidature.id}" value="annulee" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false"/><br/>
                                Liste d'attente :<input type="radio" name="validation_${candidature.id}" id="validation_${candidature.id}" value="listeAttente" onmousedown="this.__chk = this.checked" onclick="if (this.__chk) this.checked = false" />
                            </td>
                    </tr>
                    #{/list}

                </tbody>
            </table>
            <br />
            <input type="submit" value="Enregistrer" />
        #{/form}
    </div>
</div>    
#{/if}

#{else}
<div class="empty">
    <p>Aucune candidature pr&eacute;sente.</p>
</div>
#{/else}
<script>
function afficherList(id){
	document.getElementById("listePriorite"+id).style.display="block";								        				   			
}

function savePriorite(id){
	var val=document.getElementById("priorite"+id).options[document.getElementById("priorite"+id).selectedIndex].value;
	$('#tdChange'+id).load("/priorite/"+id+'&'+val)
}
</script>